import api from '../index'
import type { ResponseData, pageParam, RequestFromType } from '../index'
import type { GoodsItem } from './goods'
// 我的优惠劵列表
export const getCouponList = (params : any) =>
	api.get('customer/api/activity/coupon/list', { params })

// 领取优惠劵
export const receiveCoupon = (code : string) =>
	api.post(`customer/api/activity/coupon/receive/${code}`)

// 优惠劵详情
export const getCouponDetail = (code : number | string) =>
	api.get(`customer/api/activity/coupon/info/${code}`)

//通过商品ID或者购物车ID查询可用的优惠劵
export const getCustomerCoupon = (params : any) =>
	api.get('customer/api/activity/coupon/query', { params })
export interface CouponsItem  {
	name : string
	type : 1 | 2
	amount : number
	minPoint : number
	discountScale : number
	endTime ?: string
	id : string
	platformType : 0 | 1
	perLimit : number
	ownCount : number
	couponCode : string
	couponType : 1 | 2 | 3,
	useType : number
	useStartTime ?: string
	useEndTime ?: string
	money : number
	storeLogo : string
	storeName : string
}
//查询一个商品可领取的优惠券
export const getCouponQueryProduct = (productId : string) =>
	api.get<ResponseData<CouponsItem[]>>(`customer/api/activity/coupon/queryProduct/${productId}`,
		{
			custom: {
				auth: false
			}
		}
	)
export type ActivityItem = {
	activity : string
	id : string,
	isFlash ?: 0 | 1
}
// 查询商品的优惠信息
export const getActivityQueryTitle = (data : { productIds : string }) =>
	api.get<ResponseData<ActivityItem[]>>('customer/api/activity/query/product/title',
		{
			data,
			custom: {
				auth: false
			}
		}
	)

// 通过商品分区查找商品和优惠券
export const getCouponAndProductBySubareaId = (data : { subareaId : string | number }) =>
	api.get<ResponseData<{
		coupons : CouponsItem[],
		product : {
			rows ?: GoodsItem[]
		}
	}>>(`customer/api/activity/new/product`,
		{
			data,
			custom: {
				auth: false
			}
		}
	)